package com.resource.spring.filter;


import com.resource.constant.OfficeApiConstants;
import com.resource.spring.servlet.wrapper.GlobalRequestWrapper;
import org.springframework.web.util.UrlPathHelper;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
 * 过滤器
 * @Author: xianggaoxiong
 * @Date: 15:55 2020/9/27
 */
public class GlobalFilter implements Filter {

    private final UrlPathHelper urlPathHelper = new UrlPathHelper();

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        request.setAttribute(OfficeApiConstants.API_BEGIN_TIME, System.currentTimeMillis());
        String requestUri = urlPathHelper.getOriginatingRequestUri(req);
        request.setAttribute(OfficeApiConstants.API_REQURL, requestUri);
        GlobalRequestWrapper xssRequest = new GlobalRequestWrapper((HttpServletRequest) request);
        chain.doFilter(request, response);
    }

}